package cn.edu.swufe.stu2025.finalwork;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class EditNoteActivity extends AppCompatActivity {
    private EditText editTitle,editContent;
    Button saveButton;
    final private String TAG="EditNoteActivity";
    protected void onCreate(Bundle oddNote){
        super.onCreate(oddNote);
        setContentView(R.layout.edit_note);

        editTitle = findViewById(R.id.edit_title);
        editContent = findViewById(R.id.edit_content);
        saveButton = findViewById(R.id.save);
        // 获取数据
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        String content = intent.getStringExtra("content");
        Log.i(TAG, "onCreate: title:"+ title + " content:" + content);
        editTitle.setText(title);
        editContent.setText(content);

        saveButton.setOnClickListener(v ->{
            Intent intent2 = new Intent();
            intent2.putExtra("title",editTitle.getText().toString());
            intent2.putExtra("content",editContent.getText().toString());
            intent2.putExtra("position", getIntent().getIntExtra("position",-1));
            setResult(RESULT_OK , intent2);
            finish();
        });

    }
}
